
#ifndef _World_H_
#define _World_H_

#include "WorldObject.h"
#include "Player.h"
#include "Map.h"

#include <map>
#include <SDL/SDL.h>

class World {
  public:
    static World& instance(void);
    static void reset(void);

    void load(void);
    void update(void);
    void render(void);

    void handleKeyInput(SDLKey key);

    // The point on the map which the camera should be pointing at
    // currently. This is usually the position of the Player ship, but 
    // at times may be different (spectator mode or when a player is 
    // waiting to respawn.
    Vector2D getCurrentFocusPoint(void) const;

    Player* getControlPlayer(void) const;

    WorldObjectPointer addObject(WorldObject *object);
    
    WorldObject* getObject(unsigned id) const;
    std::vector<WorldObject*> getAllObjectsOfType(WorldObjectType type) const;    
    std::vector<WorldObject*> getObjectsInVicinity(Vector2D p) const;
    Map* getMap(void) const;

    // Kill anything that can collide with a ship at a given point.
    void telefrag(Vector2D position, float radius);    

  private:
   
    // all of the renderable and updatable dynamic objects in the world
    // eg: ships, weapons, powerups, etc.
    std::map<unsigned, WorldObject*> world_objects; 

    // TODO: this prolly needs to be moved out to Teams.
    std::vector<Player*> all_players;
    Player *my_player;

    Map *my_map;


    void handleInput(void);
    void createPlayer(void);

    // Private constructors since this is a singleton
    World();
    World(const World&);
    World& operator=(const World&);
    ~World();
};

#endif

